package com.zxj.geekstudy.mysql;

import com.zxj.geekstudy.mysql.service.Student2Service;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.math.BigDecimal;

/**
 * 9.（必做）读写分离 - 动态切换数据源版本 1.0
 */
public class TestMySQLApplication {

    public static void main(String[] args) throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContextMySQL.xml");

        // 未使用AbstractRoutingDataSource
//        StudentService studentService = applicationContext.getBean(StudentService.class);
//        System.out.println(studentService.insert("stu1", new BigDecimal(10)));
//        System.out.println(studentService.query("stu1"));

        // 使用AbstractRoutingDataSource
        Student2Service student2Service = applicationContext.getBean(Student2Service.class);
        System.out.println(student2Service.insert("stu1", new BigDecimal(10)));
        System.out.println(student2Service.query("stu1"));

    }

}
